﻿
using NPOI.SS.Formula;
using ProjectScheduling_web.model;

namespace ProjectScheduling_web.dao
{
    public class ProductDao : BaseDao<Product>
    {
        public static readonly ProductDao Base = new();
        public PageData<Product> Search(int page, int row, int categoryId, string key)
        {
            int total = 0;
            var data = Db.Queryable<Product>()
                        .WhereIF(categoryId > 0, it => it.CatetoryId == categoryId)
                        .WhereIF(!string.IsNullOrEmpty(key), it =>it.Name!=null && it.Name.Contains(key))
                        .OrderByDescending(it=>it.Id)
                        .ToPageList(page, row, ref total);
            return new()
            {
                Items = data,
                Total = total
            };
        }
    }
}
